﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:treeView="clr-namespace:TreeView">

    <Style TargetType="treeView:TreeView">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="treeView:TreeView">
                    <ListBox x:Name="PART_TreeList" 
                             ScrollViewer.VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" 
                             ScrollViewer.HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                             ItemsSource="{TemplateBinding ItemsSource}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <treeView:TreeViewItem x:Name="PART_Item"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 

    <Style TargetType="treeView:TreeViewItem">

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="treeView:TreeViewItem">
                    <Border Margin="20,0,0,0" BorderThickness="3,0,0,0" BorderBrush="{StaticResource PhoneAccentBrush}" >
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="States">
                                <VisualState x:Name="Expanded">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ItemsList"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Collapsed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ItemsList"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <StackPanel>

                            <ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}"
                                            Content="{TemplateBinding DataContext}"
                                            Foreground="{TemplateBinding Foreground}"
                                            HorizontalContentAlignment="Left"
                                            x:Name="PART_Header"/>

                            <ListBox x:Name="PART_ItemsList" Visibility="Collapsed"
                                     ScrollViewer.VerticalScrollBarVisibility="Disabled"
                                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                     Foreground="{TemplateBinding Foreground}"
                                     ItemsSource="{TemplateBinding ItemsSource}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <treeView:TreeViewItem x:Name="PART_Item"/>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>